/*
 * RtcpRtpSocket.h
 *
 *  Created on: 2018年5月14日
 *      Author: zhengboyuan
 */

#ifndef RTCPRTPSOCKET_H_
#define RTCPRTPSOCKET_H_

#include "BasicRtpSocket.h"
#include <memory>
#include "RtpPacketPtr.h"
//#include "TThread.h"
#include "OrderCache.h"
#include "UdpSendDelay.h"


class JRTPSession;


namespace av
{

class RtcpRtpSocket: public BasicRtpSocket //, public comn::Thread
{
public:
	RtcpRtpSocket();
	virtual ~RtcpRtpSocket();

	virtual bool open(const char* ip, int port);
	virtual void close();
	virtual bool isOpen();

	virtual NetAddress getLocalAddr();

	virtual bool send(RtpPacket& packet, int ms);

	virtual bool recv(RtpPacketHandler handler, int ms);

	virtual bool isConnected();

	virtual void setSsrc(uint32_t ssrc);

	virtual bool setPeer(const char* ip, int port);

	virtual void abort();

protected:
    bool openRtpSession(uint16_t port);
	void closeRtpSession();

	void poll();

	void readAndHandle(int ms);

	void onRtpPacket(jrtplib::RTPPacket* pPacket);

	void clearCache();

	void addDestination(const std::string& ip, int port);

protected:
	NetAddress	m_localAddr;
	std::shared_ptr< JRTPSession >  m_session;

	bool	m_working;
	OrderCache	m_rtpCache;
    
    UdpSendDelay    m_sendDelay;

};


} /* namespace av */

#endif /* RTCPRTPSOCKET_H_ */
